package c_;

import java.io.*;
import java.util.Properties;

public class PropertiesDemo {
    public static void main(String[] args) throws IOException {
        //读取配置文件中的信息

        //1.创建属性集对象
        Properties pro = new Properties();
        /*2.通过流加载配置文件
            "pro.properties":默认存在工程下
            pro.properties存在src下

         */
        //2.1获取配置文件路径 - 方式一
        String path = PropertiesDemo.class.getClassLoader().getResource("pro.properties").getPath();

        //方式二:
        InputStream rs = PropertiesDemo.class.getClassLoader().getResourceAsStream(path);

        //FileInputStream fis = new FileInputStream(path);
        InputStreamReader isr = new InputStreamReader(new FileInputStream(path));
        pro.load(isr);
        //3.获取属性集中的内容
        String username = pro.getProperty("username");
        System.out.println(username);
    }
}
